package com.yiwyn.validemo.service;

import com.yiwyn.validemo.domain.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.validation.ConstraintViolation;
import javax.validation.Validator;
import java.util.Set;


@Service
public class AService {

    @Autowired
    private  Validator validator;


    public String test() {

        User user = new User();

        Set<ConstraintViolation<User>> validate = validator.validate(user);

        StringBuilder builder = new StringBuilder();

        for (ConstraintViolation<User> userConstraintViolation : validate) {
            builder.append(userConstraintViolation.getPropertyPath()).append(userConstraintViolation.getMessage());
        }
        return builder.toString();
    }


}
